<?php

namespace app\admin\logic;

/**
 * 学分模块 逻辑（学生端）
 */
class Credit extends AdminBase
{
    
    /**
     * 获取待认证学分列表
     */
    public function getCreditList($where = [], $field = true, $order = '', $paginate = 0)
    {
        
        return $this->modelCredit->getList($where, $field, $order, $paginate);
    }
    
    /**
     * 待认证学分信息编辑
     */
    public function creditEdit($data = [])
    {
        
        $validate_result = $this->validateCredit->scene('edit')->check($data);
        
        if (!$validate_result) {
            
            return [RESULT_ERROR, $this->validateCredit->getError()];
        }
        
        $url = url('creditList');
        
        $result = $this->modelCredit->setInfo($data);
        
        $handle_text = empty($data['id']) ? '新增' : '编辑';
        
        $result && action_log($handle_text, '学分申请' . $handle_text . '，name：' . $data['name']);
        
        return $result ? [RESULT_SUCCESS, '操作成功', $url] : [RESULT_ERROR, $this->modelCredit->getError()];
    }

    /**
     * 获取待认证学分信息
     */
    public function getCreditInfo($where = [], $field = true)
    {
        
        return $this->modelCredit->getInfo($where, $field);
    }
    
    /**
     * 待认证学分删除
     */
    public function creditDel($where = [])
    {
        
        $result = $this->modelCredit->deleteInfo($where);
        
        $result && action_log('删除', '待认证学分删除' . '，where：' . http_build_query($where));
        
        return $result ? [RESULT_SUCCESS, '删除成功'] : [RESULT_ERROR, $this->modelCredit->getError()];
    }


}
